/**
 * Copyright (C) 2016-2019 DSpot Sp. z o.o
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.dspot.declex.transform.writer;

import org.ohosannotations.holder.GeneratedClassHolder;

import java.io.IOException;
import java.io.Writer;

/**
 * 模板转换编辑器
 *
 * @since 2021-07-13
 */
public class BaseTemplateTransformWriter<T extends GeneratedClassHolder> extends Writer {
    private Writer out;
    /**
     * 持有者
     */
    protected T holder;
    /**
     * 字符码
     */
    protected String strCode = "";

    /**
     * 构造方法
     *
     * @param out 输出者
     * @param holder 操作者
     */
    public BaseTemplateTransformWriter(Writer out, T holder) {
        this.holder = holder;
        this.out = out;
    }

    /**
     * 写IO流
     *
     * @param cbuf 字符数组
     * @param off 关闭位置
     * @param len 长度
     * @throws IOException IO异常
     */
    public void write(char[] cbuf, int off, int len)
        throws IOException {

        strCode = strCode + new String(cbuf, off, len);
    }

    /**
     * 刷新
     *
     * @throws IOException IO异常
     */
    public void flush() throws IOException {
        out.flush();
    }

    /**
     * 关闭
     */
    public void close() {
    }
}
